<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>智能控制中心 - 机器人状态</title>
  <!-- 引入Tailwind CSS -->
  <script src="https://cdn.tailwindcss.com"></script>
  <!-- 引入Font Awesome -->
  <link href="https://cdn.jsdelivr.net/npm/font-awesome@4.7.0/css/font-awesome.min.css" rel="stylesheet">
  
  <!-- 配置Tailwind -->
  <script>
    tailwind.config = {
      theme: {
        extend: {
          colors: {
            primary: '#165DFF',
            secondary: '#0F172A',
            success: '#52C41A',
            warning: '#FAAD14',
            danger: '#FF4D4F',
            robot: {
              online: '#52C41A',
              offline: '#FF4D4F',
              idle: '#FAAD14',
              working: '#165DFF'
            }
          },
          fontFamily: {
            inter: ['Inter', 'system-ui', 'sans-serif'],
          },
        },
      }
    }
  </script>
  
  <style type="text/tailwindcss">
    @layer utilities {
      .content-auto {
        content-visibility: auto;
      }
      .sidebar-item-active {
        @apply bg-primary/10 text-primary border-l-4 border-primary;
      }
      .card-hover {
        @apply transition-all duration-300 hover:shadow-lg hover:-translate-y-1;
      }
      .robot-status-indicator {
        @apply w-3 h-3 rounded-full inline-block mr-2;
      }
      .fade-in {
        animation: fadeIn 0.5s ease-in-out;
      }
      @keyframes fadeIn {
        from { opacity: 0; transform: translateY(10px); }
        to { opacity: 1; transform: translateY(0); }
      }
    }
  </style>
</head>

<body class="font-inter bg-gray-50 text-gray-800 min-h-screen flex overflow-hidden">
  <!-- 左侧导航栏 -->
  <aside class="bg-white w-64 shadow-md z-10 hidden md:block transition-all duration-300 ease-in-out">
    <!-- 品牌标识 -->
    <div class="p-5 border-b border-gray-200">
      <div class="flex items-center space-x-3">
        <div class="w-10 h-10 rounded-lg bg-primary flex items-center justify-center">
          <i class="fa fa-cogs text-white text-xl"></i>
        </div>
        <h1 class="text-xl font-bold text-secondary">智能控制中心</h1>
      </div>
    </div>
    
    <!-- 导航菜单 -->
    <nav class="py-6 px-3">
      <p class="text-xs uppercase text-gray-500 font-semibold px-4 mb-3">控制功能</p>
      
      <a href="#elevator" class="flex items-center px-4 py-3 mb-1 rounded-md text-gray-600 hover:bg-gray-100 transition-colors cursor-pointer">
        <i class="fa fa-building-o w-6 text-center"></i>
        <span class="ml-3">电梯控制</span>
      </a>
      
      <a href="#gate" class="flex items-center px-4 py-3 mb-1 rounded-md text-gray-600 hover:bg-gray-100 transition-colors cursor-pointer">
        <i class="fa fa-sign-out w-6 text-center"></i>
        <span class="ml-3">闸机控制</span>
      </a>
      
      <a href="#robot" class="sidebar-item-active flex items-center px-4 py-3 mb-1 rounded-md cursor-pointer">
        <i class="fa fa-android w-6 text-center"></i>
        <span class="ml-3">机器人状态</span>
      </a>
      
      <div class="mt-8 pt-6 border-t border-gray-200">
        <p class="text-xs uppercase text-gray-500 font-semibold px-4 mb-3">系统</p>
        
        <a href="#settings" class="flex items-center px-4 py-3 mb-1 rounded-md text-gray-600 hover:bg-gray-100 transition-colors cursor-pointer">
          <i class="fa fa-cog w-6 text-center relative">
            <span id="updateIndicator" class="update-badge hidden">!</span>
          </i>
          <span class="ml-3">设置</span>
        </a>
        
        <a href="#" class="flex items-center px-4 py-3 mb-1 rounded-md text-gray-600 hover:bg-gray-100 transition-colors cursor-pointer">
          <i class="fa fa-question-circle w-6 text-center"></i>
          <span class="ml-3">帮助中心</span>
        </a>
      </div>
    </nav>
  </aside>
  
  <!-- 主内容区域 -->
  <main class="flex-1 flex flex-col overflow-hidden">
    <!-- 顶部状态栏 -->
    <header class="bg-white shadow-sm px-6 py-4 flex justify-between items-center">
      <button class="md:hidden text-gray-500 focus:outline-none" id="menu-toggle">
        <i class="fa fa-bars text-xl"></i>
      </button>
      
      <div class="flex items-center space-x-6">
        <div class="relative">
          <input type="text" placeholder="搜索..." class="pl-10 pr-4 py-2 rounded-lg border border-gray-300 focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary w-64 transition-all">
          <i class="fa fa-search absolute left-3 top-1/2 transform -translate-y-1/2 text-gray-400"></i>
        </div>
        
        <div class="flex items-center space-x-4">
          <button class="relative p-2 text-gray-500 hover:text-primary transition-colors">
            <i class="fa fa-bell text-xl"></i>
            <span class="absolute top-1 right-1 w-2 h-2 bg-danger rounded-full"></span>
          </button>
          
          <div class="flex items-center space-x-2">
            <img src="https://picsum.photos/id/1005/40/40" alt="用户头像" class="w-8 h-8 rounded-full object-cover">
            <span class="hidden md:inline font-medium">管理员</span>
          </div>
        </div>
      </div>
    </header>
    
    <!-- 内容滚动区域 -->
    <div class="flex-1 overflow-y-auto p-6 bg-gray-50">
      <!-- 机器人状态页面 -->
      <section id="robot" class="mb-10">
        <div class="flex justify-between items-center mb-6">
          <h2 class="text-2xl font-bold text-secondary">机器人状态</h2>
          <div class="text-sm text-gray-500">
            <span id="current-time-robot">2025-11-18 10:30:00</span>
          </div>
        </div>
        
        <!-- 操作按钮区 -->
        <div class="mb-6 flex justify-between items-center">
          <div>
            <p class="text-gray-600"><span id="onlineCount" class="font-medium text-robot-online">3</span> 台在线，<span id="totalCount" class="font-medium">5</span> 台总数</p>
          </div>
          <button id="addRobotBtn" class="px-4 py-2 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors flex items-center">
            <i class="fa fa-plus mr-2"></i> 添加机器人设备
          </button>
        </div>
        
        <!-- 机器人列表 -->
        <div id="robotsContainer" class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-6">
          <!-- 机器人1 -->
          <div class="bg-white rounded-xl shadow-sm overflow-hidden card-hover fade-in">
            <div class="p-5 border-b border-gray-100">
              <div class="flex justify-between items-start">
                <div class="flex items-center">
                  <div class="w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center mr-3">
                    <i class="fa fa-android text-primary text-xl"></i>
                  </div>
                  <div>
                    <h3 class="font-semibold">配送机器人 R-001</h3>
                    <p class="text-sm text-gray-500">ID: RB2025001</p>
                  </div>
                </div>
                <span class="px-2 py-1 bg-robot-online/10 text-robot-online text-xs rounded-full">
                  <span class="robot-status-indicator bg-robot-online"></span>在线
                </span>
              </div>
            </div>
            <div class="p-5">
              <div class="space-y-4">
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">当前状态</h4>
                  <p class="font-medium">执行配送任务</p>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">电池电量</h4>
                  <div class="flex items-center">
                    <div class="w-full bg-gray-200 rounded-full h-2.5 mr-2">
                      <div class="bg-robot-working h-2.5 rounded-full" style="width: 78%"></div>
                    </div>
                    <span class="text-sm font-medium">78%</span>
                  </div>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">任务进度</h4>
                  <div class="flex items-center">
                    <div class="w-full bg-gray-200 rounded-full h-2.5 mr-2">
                      <div class="bg-primary h-2.5 rounded-full" style="width: 65%"></div>
                    </div>
                    <span class="text-sm font-medium">65%</span>
                  </div>
                </div>
              </div>
              
              <div class="mt-5 flex justify-end space-x-2">
                <button class="px-3 py-1.5 border border-gray-300 text-gray-700 rounded-lg text-sm hover:bg-gray-50 transition-colors">
                  <i class="fa fa-history mr-1"></i> 历史
                </button>
                <button class="px-3 py-1.5 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
                  <i class="fa fa-cog mr-1"></i> 控制
                </button>
              </div>
            </div>
          </div>
          
          <!-- 机器人2 -->
          <div class="bg-white rounded-xl shadow-sm overflow-hidden card-hover fade-in">
            <div class="p-5 border-b border-gray-100">
              <div class="flex justify-between items-start">
                <div class="flex items-center">
                  <div class="w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center mr-3">
                    <i class="fa fa-android text-primary text-xl"></i>
                  </div>
                  <div>
                    <h3 class="font-semibold">清洁机器人 R-002</h3>
                    <p class="text-sm text-gray-500">ID: RB2025002</p>
                  </div>
                </div>
                <span class="px-2 py-1 bg-robot-idle/10 text-robot-idle text-xs rounded-full">
                  <span class="robot-status-indicator bg-robot-idle"></span>空闲
                </span>
              </div>
            </div>
            <div class="p-5">
              <div class="space-y-4">
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">当前状态</h4>
                  <p class="font-medium">等待任务分配</p>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">电池电量</h4>
                  <div class="flex items-center">
                    <div class="w-full bg-gray-200 rounded-full h-2.5 mr-2">
                      <div class="bg-robot-working h-2.5 rounded-full" style="width: 92%"></div>
                    </div>
                    <span class="text-sm font-medium">92%</span>
                  </div>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">今日完成</h4>
                  <p class="font-medium">5 个清洁任务</p>
                </div>
              </div>
              
              <div class="mt-5 flex justify-end space-x-2">
                <button class="px-3 py-1.5 border border-gray-300 text-gray-700 rounded-lg text-sm hover:bg-gray-50 transition-colors">
                  <i class="fa fa-history mr-1"></i> 历史
                </button>
                <button class="px-3 py-1.5 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
                  <i class="fa fa-cog mr-1"></i> 控制
                </button>
              </div>
            </div>
          </div>
          
          <!-- 机器人3 -->
          <div class="bg-white rounded-xl shadow-sm overflow-hidden card-hover fade-in">
            <div class="p-5 border-b border-gray-100">
              <div class="flex justify-between items-start">
                <div class="flex items-center">
                  <div class="w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center mr-3">
                    <i class="fa fa-android text-primary text-xl"></i>
                  </div>
                  <div>
                    <h3 class="font-semibold">安防机器人 R-003</h3>
                    <p class="text-sm text-gray-500">ID: RB2025003</p>
                  </div>
                </div>
                <span class="px-2 py-1 bg-robot-offline/10 text-robot-offline text-xs rounded-full">
                  <span class="robot-status-indicator bg-robot-offline"></span>离线
                </span>
              </div>
            </div>
            <div class="p-5">
              <div class="space-y-4">
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">当前状态</h4>
                  <p class="font-medium text-danger">连接中断</p>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">最后在线</h4>
                  <p class="font-medium">2025-11-18 08:45:12</p>
                </div>
                <div>
                  <h4 class="text-sm text-gray-500 mb-1">故障提示</h4>
                  <p class="font-medium text-danger">通讯模块异常</p>
                </div>
              </div>
              
              <div class="mt-5 flex justify-end space-x-2">
                <button class="px-3 py-1.5 border border-gray-300 text-gray-700 rounded-lg text-sm hover:bg-gray-50 transition-colors">
                  <i class="fa fa-history mr-1"></i> 历史
                </button>
                <button class="px-3 py-1.5 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
                  <i class="fa fa-refresh mr-1"></i> 重连
                </button>
              </div>
            </div>
          </div>
        </div>
      </section>
    </div>
  </main>
  
  <!-- 添加机器人模态框 -->
  <div id="addRobotModal" class="fixed inset-0 bg-black bg-opacity-50 z-50 hidden flex items-center justify-center p-4">
    <div class="bg-white rounded-xl shadow-lg w-full max-w-md fade-in">
      <div class="p-5 border-b border-gray-100 flex justify-between items-center">
        <h3 class="text-lg font-semibold">添加机器人设备</h3>
        <button id="closeModalBtn" class="text-gray-500 hover:text-gray-700 transition-colors">
          <i class="fa fa-times text-xl"></i>
        </button>
      </div>
      <div class="p-5">
        <form id="addRobotForm" class="space-y-4">
          <div>
            <label for="robotName" class="block text-sm font-medium text-gray-700 mb-1">机器人名称</label>
            <input type="text" id="robotName" name="robotName" placeholder="例如：配送机器人 R-004" 
                  class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"
                  required>
          </div>
          <div>
            <label for="robotType" class="block text-sm font-medium text-gray-700 mb-1">机器人类型</label>
            <select id="robotType" name="robotType" 
                  class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"
                  required>
              <option value="">请选择类型</option>
              <option value="delivery">配送机器人</option>
              <option value="cleaning">清洁机器人</option>
              <option value="security">安防机器人</option>
              <option value="service">服务机器人</option>
            </select>
          </div>
          <div>
            <label for="robotId" class="block text-sm font-medium text-gray-700 mb-1">设备ID</label>
            <input type="text" id="robotId" name="robotId" placeholder="例如：RB2025004" 
                  class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"
                  required>
          </div>
          <div>
            <label for="robotStatus" class="block text-sm font-medium text-gray-700 mb-1">初始状态</label>
            <select id="robotStatus" name="robotStatus" 
                  class="w-full px-4 py-2 border border-gray-300 rounded-lg focus:outline-none focus:ring-2 focus:ring-primary/50 focus:border-primary transition-all"
                  required>
              <option value="online">在线</option>
              <option value="idle">空闲</option>
              <option value="offline">离线</option>
            </select>
          </div>
        </form>
      </div>
      <div class="p-5 border-t border-gray-100 flex justify-end space-x-3">
        <button id="cancelAddBtn" class="px-4 py-2 border border-gray-300 text-gray-700 rounded-lg text-sm hover:bg-gray-50 transition-colors">
          取消
        </button>
        <button id="confirmAddBtn" class="px-4 py-2 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
          确认添加
        </button>
      </div>
    </div>
  </div>
  
  <!-- 移动端侧边栏遮罩 -->
  <div id="sidebar-overlay" class="fixed inset-0 bg-black bg-opacity-50 z-20 hidden md:hidden"></div>
  
  <script>
    document.addEventListener('DOMContentLoaded', function() {
      // 元素引用
      const addRobotBtn = document.getElementById('addRobotBtn');
      const addRobotModal = document.getElementById('addRobotModal');
      const closeModalBtn = document.getElementById('closeModalBtn');
      const cancelAddBtn = document.getElementById('cancelAddBtn');
      const confirmAddBtn = document.getElementById('confirmAddBtn');
      const robotsContainer = document.getElementById('robotsContainer');
      const onlineCountEl = document.getElementById('onlineCount');
      const totalCountEl = document.getElementById('totalCount');
      
      // 机器人计数器
      let robotCounter = 3; // 当前已有3台机器人
      let onlineCounter = 2; // 当前在线2台机器人
      
      // 打开添加机器人模态框
      addRobotBtn.addEventListener('click', () => {
        addRobotModal.classList.remove('hidden');
        // 重置表单
        document.getElementById('addRobotForm').reset();
      });
      
      // 关闭模态框
      function closeModal() {
        addRobotModal.classList.add('hidden');
      }
      
      closeModalBtn.addEventListener('click', closeModal);
      cancelAddBtn.addEventListener('click', closeModal);
      
      // 点击模态框外部关闭
      addRobotModal.addEventListener('click', (e) => {
        if (e.target === addRobotModal) {
          closeModal();
        }
      });
      
      // 确认添加机器人
      confirmAddBtn.addEventListener('click', () => {
        // 获取表单数据
        const robotName = document.getElementById('robotName').value;
        const robotType = document.getElementById('robotType').value;
        const robotId = document.getElementById('robotId').value;
        const robotStatus = document.getElementById('robotStatus').value;
        
        // 简单验证
        if (!robotName || !robotType || !robotId || !robotStatus) {
          alert('请填写完整的机器人信息');
          return;
        }
        
        // 创建机器人类型文本映射
        const typeMap = {
          'delivery': '配送机器人',
          'cleaning': '清洁机器人',
          'security': '安防机器人',
          'service': '服务机器人'
        };
        
        // 创建状态样式映射
        const statusMap = {
          'online': { 
            class: 'robot-online',
            text: '在线',
            bgClass: 'bg-robot-online/10',
            textClass: 'text-robot-online',
            indicatorClass: 'bg-robot-online'
          },
          'idle': { 
            class: 'robot-idle',
            text: '空闲',
            bgClass: 'bg-robot-idle/10',
            textClass: 'text-robot-idle',
            indicatorClass: 'bg-robot-idle'
          },
          'offline': { 
            class: 'robot-offline',
            text: '离线',
            bgClass: 'bg-robot-offline/10',
            textClass: 'text-robot-offline',
            indicatorClass: 'bg-robot-offline'
          }
        };
        
        // 根据状态设置初始信息
        let statusInfo, batteryLevel, extraInfo, actionBtn;
        const statusConfig = statusMap[robotStatus];
        
        if (robotStatus === 'online') {
          statusInfo = '执行任务中';
          batteryLevel = Math.floor(Math.random() * 30) + 70; // 70-100%
          extraInfo = `<div>
                        <h4 class="text-sm text-gray-500 mb-1">任务进度</h4>
                        <div class="flex items-center">
                          <div class="w-full bg-gray-200 rounded-full h-2.5 mr-2">
                            <div class="bg-primary h-2.5 rounded-full" style="width: ${Math.floor(Math.random() * 70) + 10}%"></div>
                          </div>
                          <span class="text-sm font-medium">${Math.floor(Math.random() * 70) + 10}%</span>
                        </div>
                      </div>`;
          actionBtn = '<i class="fa fa-cog mr-1"></i> 控制';
          onlineCounter++;
        } else if (robotStatus === 'idle') {
          statusInfo = '等待任务分配';
          batteryLevel = Math.floor(Math.random() * 30) + 70; // 70-100%
          extraInfo = `<div>
                        <h4 class="text-sm text-gray-500 mb-1">今日完成</h4>
                        <p class="font-medium">${Math.floor(Math.random() * 8) + 1} 个任务</p>
                      </div>`;
          actionBtn = '<i class="fa fa-cog mr-1"></i> 控制';
          onlineCounter++;
        } else { // offline
          statusInfo = '连接中断';
          batteryLevel = Math.floor(Math.random() * 40) + 10; // 10-50%
          extraInfo = `<div>
                        <h4 class="text-sm text-gray-500 mb-1">最后在线</h4>
                        <p class="font-medium">${new Date().toLocaleString('zh-CN').replace(',', '')}</p>
                      </div>
                      <div>
                        <h4 class="text-sm text-gray-500 mb-1">故障提示</h4>
                        <p class="font-medium text-danger">通讯模块异常</p>
                      </div>`;
          actionBtn = '<i class="fa fa-refresh mr-1"></i> 重连';
        }
        
        // 创建新机器人卡片
        const newRobotCard = document.createElement('div');
        newRobotCard.className = 'bg-white rounded-xl shadow-sm overflow-hidden card-hover fade-in';
        newRobotCard.innerHTML = `
          <div class="p-5 border-b border-gray-100">
            <div class="flex justify-between items-start">
              <div class="flex items-center">
                <div class="w-10 h-10 rounded-full bg-primary/10 flex items-center justify-center mr-3">
                  <i class="fa fa-android text-primary text-xl"></i>
                </div>
                <div>
                  <h3 class="font-semibold">${robotName}</h3>
                  <p class="text-sm text-gray-500">ID: ${robotId}</p>
                </div>
              </div>
              <span class="px-2 py-1 ${statusConfig.bgClass} ${statusConfig.textClass} text-xs rounded-full">
                <span class="robot-status-indicator ${statusConfig.indicatorClass}"></span>${statusConfig.text}
              </span>
            </div>
          </div>
          <div class="p-5">
            <div class="space-y-4">
              <div>
                <h4 class="text-sm text-gray-500 mb-1">当前状态</h4>
                <p class="font-medium ${robotStatus === 'offline' ? 'text-danger' : ''}">${statusInfo}</p>
              </div>
              <div>
                <h4 class="text-sm text-gray-500 mb-1">电池电量</h4>
                <div class="flex items-center">
                  <div class="w-full bg-gray-200 rounded-full h-2.5 mr-2">
                    <div class="bg-robot-working h-2.5 rounded-full" style="width: ${batteryLevel}%"></div>
                  </div>
                  <span class="text-sm font-medium">${batteryLevel}%</span>
                </div>
              </div>
              ${extraInfo}
            </div>
            
            <div class="mt-5 flex justify-end space-x-2">
              <button class="px-3 py-1.5 border border-gray-300 text-gray-700 rounded-lg text-sm hover:bg-gray-50 transition-colors">
                <i class="fa fa-history mr-1"></i> 历史
              </button>
              <button class="px-3 py-1.5 bg-primary text-white rounded-lg text-sm hover:bg-primary/90 transition-colors">
                ${actionBtn}
              </button>
            </div>
          </div>
        `;
        
        // 添加到容器
        robotsContainer.appendChild(newRobotCard);
        
        // 更新计数器
        robotCounter++;
        onlineCountEl.textContent = onlineCounter;
        totalCountEl.textContent = robotCounter;
        
        // 关闭模态框
        closeModal();
      });
      
      // 更新当前时间
      function updateTime() {
        const now = new Date();
        const timeString = now.toLocaleString('zh-CN', {
          year: 'numeric',
          month: '2-digit',
          day: '2-digit',
          hour: '2-digit',
          minute: '2-digit',
          second: '2-digit',
          hour12: false
        }).replace(',', '');
        
        document.getElementById('current-time-robot').textContent = timeString;
      }
      
      // 初始化时间并每秒更新
      updateTime();
      setInterval(updateTime, 1000);
      
      // 导航菜单切换逻辑
      const menuToggle = document.getElementById('menu-toggle');
      const sidebar = document.querySelector('aside');
      const sidebarOverlay = document.getElementById('sidebar-overlay');
      
      menuToggle.addEventListener('click', () => {
        sidebar.classList.toggle('hidden');
        sidebar.classList.toggle('absolute');
        sidebar.classList.toggle('top-0');
        sidebar.classList.toggle('left-0');
        sidebar.classList.toggle('h-full');
        sidebarOverlay.classList.toggle('hidden');
      });
      
      sidebarOverlay.addEventListener('click', () => {
        sidebar.classList.add('hidden');
        sidebarOverlay.classList.add('hidden');
      });
    });
  </script>
</body>
</html>